package treeview;

import search.Visitor;

import java.awt.*;
import java.util.ArrayList;

/**
 * Created by Pavel Nikolaev
 */
public abstract class AbstractContainer extends AbstractNodeView {
    protected ArrayList<NodeView> myNodeViews;

    protected AbstractContainer() {
        this.myNodeViews = new ArrayList<NodeView>();
    }

    public void add(NodeView view) {
        myNodeViews.add(view);
    }

    public void print(int level) {
        super.print(level);
        int childLevel = level + 1;
        for (NodeView view : myNodeViews) {
            view.print(childLevel);
        }
    }

    public int countChildren() {return myNodeViews.size();}

    public NodeView getChild(int index) {return myNodeViews.get(index);}

    public void paint(Graphics g) {
        for (NodeView child : myNodeViews) child.paint(g);
    }

    @Override
    public void accept(Visitor visitor) {
        for (NodeView child : myNodeViews) child.accept(visitor);
    }
}
